<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Cart;

class CartController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {   
        // Cart::destroy();
        // $res = Cart::add('1', 'akylone', 1, 2);
       $products = [
            1=>['id'=>2,'name'=>'axylone','price'=>1,'des'=>'限量版'],
            2=>['id'=>3,'name'=>'法拉利','price'=>2,'des'=>'豪车与美女'],
            3=>['id'=>4,'name'=>'兰博基里','price'=>3,'des'=>'速度与激情'],
       ];
        return view('shop.cartlist',['products'=>$products]);
        // dd($res);
        // dd(Cart::content());
        // dd(Cart::count());
        // dd(Cart::subtotal());

        // dd(Cart::get($rowId));

    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function addcart($id)
    {
        $products = [
            2=>['id'=>2,'name'=>'axylone','price'=>1,'des'=>'限量版'],
            3=>['id'=>3,'name'=>'法拉利','price'=>2,'des'=>'豪车与美女'],
            4=>['id'=>4,'name'=>'兰博基里','price'=>3,'des'=>'速度与激情'],
       ];
       $product = $products[$id];
       // dd($product);

       // $product['pty'] = 1;
       Cart::add($product['id'],$product['name'], 1,$product['price']);
         return redirect('/shop/cart');
    }

    public function del()
    {
        Cart::destroy();
        return back();
    }

    public function removecart($rowId)
    {
        Cart::remove($rowId);
        return back();
    }
    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        echo 555;
    }

    public function cart()
    {
        // echo 111;
        $carts = Cart::content();
        $total = Cart::total();
        $count = Cart::count();
        return view('shop.cart',['carts'=>$carts,'total'=>$total,'count'=>$count]);

    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
